package com.springboot.util;

import com.zhenzi.sms.ZhenziSmsClient;

import java.util.HashMap;
import java.util.Map;

/**
 * 发送短信的工具类
 * Send_Message
 */
public class SendMessage
{
    public String sendMessage(String tel)
    {
        ZhenziSmsClient client = new ZhenziSmsClient("https://sms_developer.zhenzikj.com", "106819", "ZWRhMWQ4MTgtZDMyNS00ZjM3LTg1NGYtMGVkOTU5NDUyOGZj");
//        String code = Integer.toString((int) (Math.random() * 9999) + 1000);
        String code = "0000";
        System.out.println(code);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("number",tel);
        params.put("templateId", "1784"); //1784短信模板
        String[] templateParams = new String[2];
        templateParams[0] = code;
        templateParams[1] = "30";
        params.put("templateParams", templateParams);
        String result = null;
        try {
            result = client.send(params);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String balance = null;
        try {
            balance = client.balance();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("result = " + result);
        System.out.println("balance = " + balance);
        return code;
    }
}
